package com.qf.controller;

import com.qf.pojo.Course;
import com.qf.service.CourseService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 课程控制器
 */
@Controller
@ResponseBody
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;

    /**
     * 全查课程
     * @return
     */
    @RequestMapping("/selectAll")
    public ResultMsg selectAll(@RequestParam(required = false,defaultValue = "1",name = "page") Integer page, @RequestParam(name = "limit",required = false,defaultValue = "10") Integer limit){
        ResultMsg resultMsg = courseService.selectAll(page,limit);
        return resultMsg;
    }

    /**
     * 根据课程ID查询一条课程信息
     * @param courseId
     * @return
     */
    @RequestMapping("/selectOne")
    public ResultMsg selectOne(Integer courseId){
        return courseService.selectOne(courseId);
    }

    /**
     * 修改课程状态
     * @param courseId
     * @return
     */
    @RequestMapping("/changeCourseStatus")
    public ResultMsg changeCourseStatus(Integer courseId){
        return courseService.changeCourseStatus(courseId);
    }

    /**
     * 修改课程信息
     * @param course
     * @return
     */
//    @RequestMapping("/changeCourse")
    @PutMapping("/changeCourse")
    public ResultMsg changCourse(@RequestBody Course course){
        return courseService.changeCourse(course);
    }

    /**
     *删除一门课程
     * @param courseId
     * @return
     */
    @RequestMapping("/deleteCourse")
    public ResultMsg deleteCourse(Integer courseId){
        return courseService.deleteCourse(courseId);
    }

    /**
     * 模糊查询（根据年级名称和状态）
     * @param name
     * @param status
     * @return
     */
    @RequestMapping("/find")
    public ResultMsg find(String name,String status){
        ResultMsg resultMsg = courseService.find(name, status);
        return resultMsg;
    }

    /**
     * 新增一门课程
     * @param course
     * @return
     */
//    @RequestMapping("/add")
    @PutMapping("/add")
    public ResultMsg add(@RequestBody Course course){
        return courseService.add(course);
    }
}
